package com.liy.supercloud.ssoclient.runner;

import com.liy.framework.common.extvo.ResultVO;
import com.liy.framework.common.token.Base64Utils;
import com.liy.supercloud.ssoclient.feign.AuthorizationFeignClient;
import com.liy.supercloud.ssoclient.security.jwt.UserAuthConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AuthClientRunner implements CommandLineRunner {

    protected static Logger log = LoggerFactory.getLogger(AuthClientRunner.class);

    @Autowired
    private UserAuthConfig keyConfig;

    @Autowired
    private AuthorizationFeignClient authorizationFeignClient;


    public void run(String... args) throws Exception {
        try {
            ResultVO resultVO = this.authorizationFeignClient.getUserPublicKey(this.keyConfig.getClientId(), this.keyConfig.getClientSecret());
            log.warn("Init authentication status: " + resultVO.getMessage());
            if (resultVO.isSuccess() && resultVO.getData() != null) {
                this.keyConfig.setPubKeyByte(Base64Utils.decode(resultVO.getData().toString()));
            }
        } catch (Exception var3) {
            log.error("Init authentication key error: " + var3.getMessage(), var3);
        }

    }
}
